<template>
  <h3>{{ person}}</h3>
  <h2>姓名：{{ name }}</h2>
  <h2>年龄：{{ age }}</h2>
  <h2>薪资：{{ job.j1.salary }}</h2>
  <button @click="name += '~'">修改姓名</button>
  <button @click="age ++ ">增长年龄</button>
  <button @click="job.j1.salary ++ ">张薪</button>
</template>

<script>
import {reactive, toRef, toRefs} from 'vue'

export default {

  setup() {
    // 数据
    let person = reactive({
      name: 'achao',
      age: 18,
      job: {
        j1: {
          salary: 100
        }
      }
    })

    // 返回一个对象
    return {
      person,
      name: toRef(person, 'name'),
      // toRefs 只能简化一层
      ...toRefs(person)
    }
  }
}
</script>

<style scoped>

</style>
